package uscdb.controller;

import org.apache.log4j.Logger;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
 * 版本控制器
 * @author SYSTEM
 *
 */
import org.springframework.web.bind.annotation.ResponseBody;

import uscdb.pageModel.DataGrid;
import uscdb.pageModel.Json;
import uscdb.pageModel.Lversion;
import uscdb.pageModel.PageHelper;
import uscdb.service.VersionServiceI;

@Controller
@RequestMapping("/versionController")
public class VersionController extends BaseController {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(VersionController.class);

	@Autowired
	private VersionServiceI versionService;

	/**
	 * 添加 产品
	 * 
	 * @param lversion
	 * @return
	 */
	@RequestMapping("/add")
	@ResponseBody
	public Json add(Lversion lversion) {
		Json json = new Json();
		try {
			json = versionService.add(lversion);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			json.setMsg("系统故障，请联系管理员");
		}
		return json;
	}

	/**
	 * 修改 版本
	 * 
	 * @param product
	 * @return
	 */
	@RequestMapping("/edit")
	@ResponseBody
	public Json edit(Lversion lversion) {
		Json json = new Json();
		try {
			json = versionService.edit(lversion);
			json.setMsg("修改成功");
			json.setSuccess(true);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			json.setMsg("系统故障，请联系管理员");
		}
		return json;
	}

	/**
	 * 删除 版本
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public Json delete(String ids) {
		Json json = new Json();
		try {
			json = versionService.delete(ids);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			json.setMsg("系统故障，请联系管理员");
		}
		return json;
	}

	/**
	 * 获取 版本 数据表格
	 * 
	 * @param lversion,PageHelper
	 * @return
	 */
	@RequestMapping("/dataGrid")
	@ResponseBody
	public DataGrid dataGrid(Lversion lversion, PageHelper ph) {
		return versionService.dataGrid(lversion, ph);
	}

	/**
	 * 跳转到 version 管理页面
	 * 
	 * @return
	 */
	@RequestMapping("/manager")
	public String manager(HttpServletRequest request) {
		return "/admin/version";
	}

	/**
	 * 功能：导入logic时必须选择版本号
	 * 
	 * @param q
	 *            参数
	 * @return
	 */
	@RequestMapping("/versionCombobox")
	@ResponseBody
	public List<Lversion> versionCombobox(String productName) {
		List<Lversion> lversionList = versionService.versionCombobox(productName);
		return lversionList;
	}

}
